<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="css/index.css" />
</head>

<body>
    <div id="orientadd">
        <h2>添加房屋朝向</h2>
        <el-form ref="loginform" :model="housesOrientObj" label-width="100px" style="width:500px">
            <!-- <el-form-item label="房屋朝向编号">
                <el-input v-model="housesOrientObj.orientId"></el-input>
            </el-form-item> -->
            <el-form-item label="房屋朝向" :required="true">
                <el-input v-model="housesOrientObj.orientName" clearable ></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="insert">添加</el-button>
            </el-form-item>
            
        </el-form>
        

    </div>
    <script type="text/javascript" src="js/vue.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="js/axios.min.js"></script>

    <script type="text/javascript" src="js/common.js"></script>
 

    <script type="text/javascript">
       

        new Vue({
            
            el: "#orientadd",
            data: {
                housesOrientObj: {
                    orientId: "",
                    orientName: "",
                },
                orientList:[]
                
            },
            methods: {
               
                insert: function () {
                    let that = this;
                    var newArr;
                    let fm = new FormData();
                    axios.get("/housesOrient/selectAll").then(function (r) {
                        if (r.data.state == "success") {
                           var str = "";
                            that.orientList = r.data.housesorientlist;
                            that.orientList.forEach(function (e) {
                                str += e.orientName + ",";
                            });
                            str = str.substring(0, str.length - 1);
                            newArr = str.split(",");
                            //window.console.log(newArr);
                           if( that.housesOrientObj.orientName + '' == ""){
                               that.$message.error("输入信息不完整，请检查！");
                           }
                           else if( newArr.indexOf(that.housesOrientObj.orientName+'')!==-1){
                               that.$message.error('朝向已经存在，请重新输入！');
                              

                            }
                            else{
                                that.$message({
                                   message: "添加朝向成功！",
                                   type: "success",
                                   duration: 1000
                               });
                                // fm.append("orientId", that.housesOrientObj.orientId);
                                fm.append("orientName", that.housesOrientObj.orientName);

                               axios.post("/housesOrient/insert", fm).then(function (r) {
                                   if (r.data.state == "success") {
                                       setTimeout("location.href = 'housesOrientList.html'",1000);
                                   }
                               });
                            }
                           
                          
                        }

                    });
                   
                }
            }
        });


    </script>

</body>

</html>